package com.example.lin.day9_27.mvp.model;

import android.support.annotation.NonNull;

import com.example.lin.day9_27.pojo.ResultData;
import com.example.lin.day9_27.pojo.User;
import com.example.lin.day9_27.utils.RetrofitClient;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public class MainModel implements IMainModel {


    @Override
    public void login(String user, String psw, @NonNull final OnLoadCallback callback) {
        Disposable subscribe = RetrofitClient.getService().login(user, psw)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<ResultData<User>>() {
                    @Override
                    public void accept(ResultData<User> resultData) throws Exception {
                        callback.onSuccess(resultData);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        callback.onFaild(throwable);
                    }
                });
    }


}
